import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/index/login.vue'
import PageHome from '../views/index/homepage.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: "/login",
    name: "Login",
    component: Login
  },{
    path: "/home",
    name: "PageHome",
    component: PageHome,
    children:[
      {
        path: "/user",
        name: "User",
        component: () => import('../views/sys/user.vue')
      },
      {
        path: "/personal",
        name: "Personal",
        component: () => import('../views/index/personal.vue')
      },
      {
        path: "/role",
        name: "Role",
        component: ()=>import('../views/sys/role.vue')
      },
      {
        path: "/level",
        name: "Level",
        component: ()=>import('../views/customer/level')
      },
      {
        path: "/client",
        name: "Client",
        component: ()=>import('../views/customer/client')
      },
      {
        path: "/integration",
        name: "Integration",
        component: ()=>import('../views/customer/integration')
      },
      {
        path: "/coupon",
        name: "Coupon",
        component: ()=>import('../views/customer/coupon')
      },
      {
        path: "/menu",
        name: "Menu",
        component: ()=>import('../views/sys/menu.vue')
      },
      {
        path: "/operLog",
        name: "OperLog",
        component: () => import('../views/sys/operLog.vue')
      },
      {
        path: "/income",
        name: "Income",
        component: () => import('../views/statistics/income.vue')
      },
      {
        path: "/operationRecord",
        name: "OperationRecord",
        component: () => import('../views/statistics/operationRecord.vue')
      },
      {
        path: "/brand",
        name: "Brand",
        component: ()=>import('../views/hire/brand.vue')
      },
      {
        path: "/type",
        name: "Type",
        component: ()=>import('../views/hire/type.vue')
      },
      {
        path: "/config",
        name: "Config",
        component: ()=>import('../views/hire/config.vue')
      },
      {
        path: "/shop",
        name: "Shop",
        component: ()=>import('../views/hire/shop.vue')
      },
      {
        path: "/info",
        name: "Info",
        component: ()=>import('../views/hire/info.vue')
      },
      {
        path: "/couponRecord",
        name: "CouponRecord",
        component: ()=>import('../views/customer/couponRecord.vue')
      },
      {
        path: "/comment",
        name: "Comment",
        component: ()=>import('../views/hire/comment.vue')
      },
      {
        path: "/order",
        name: "Order",
        component: ()=>import('../views/order/order.vue')
      },
      {
        path: "/maintainShop",
        name: "Weixiuchang",
        component: ()=>import('../views/maintain/weixiuchang.vue')
      },
      {
        path: "/maintainRecord",
        name: "Weixiujilu",
        component: ()=>import('../views/maintain/weixiujilu.vue')
      },
      {
        path: "/advertisePosition",
        name: "AdvertisePosition",
        component: () => import('../views/marketing/advertisePosition.vue')
      },
      {
        path: "/question",
        name: "Question",
        component: () => import('../views/marketing/question.vue')
      },
      {
        path: "/advertise",
        name: "Advertise",
        component: () => import('../views/marketing/advertise.vue')
      },
    ]
  }

]

const router = new VueRouter({
  mode:"history",
  routes
})

//路由守卫
router.beforeEach((to,from,next)=>{
  //判断访问的地址是不是 /login  登录页面
  if (to.path==='/login'){
    return next();
  }
  //判断是否存在 token
  var item = sessionStorage.getItem("token");
  if (item){
    return next();
  }
  return next('/login');

})

export default router
